package com.zx.notification.common.mapstruct;

import com.zx.notification.common.enums.BizTypeEnum;
import com.zx.notification.common.enums.ChannelTypeEnum;
import com.zx.notification.common.model.SystemNotifications;
import com.zx.notification.common.param.SystemNotificationsParam;
import com.zx.notification.common.vo.SystemNotificationsVO;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.ReportingPolicy;

/**
 * <p>
 * description: 系统通知映射器 <br>
 * create: 2025-10-15
 * </p>
 *
 * @author zhou  xun
 */
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface SystemNotificationsMapStructMapper {

    /**
     * 将SystemNotificationsParam转换为SystemNotifications实体
     *
     * @param systemNotificationsParam 系统通知参数
     * @return SystemNotifications实体
     */
    SystemNotifications systemNotificationsParamToSystemNotifications(SystemNotificationsParam systemNotificationsParam);

    /**
     * 将SystemNotifications实体转换为SystemNotificationsVO视图对象
     *
     * @param systemNotifications 系统通知实体
     * @return SystemNotificationsVO视图对象
     */
    SystemNotificationsVO systemNotificationsToSystemNotificationsVO(SystemNotifications systemNotifications);

    /**
     * 在映射完成后，设置描述性字段
     *
     * @param systemNotifications   系统通知实体
     * @param systemNotificationsVO 系统通知VO
     */
    @AfterMapping
    default void setDescriptions(SystemNotifications systemNotifications, @MappingTarget SystemNotificationsVO systemNotificationsVO) {
        // 设置业务类型描述
        BizTypeEnum bizTypeEnum = BizTypeEnum.getEnumByCode(systemNotifications.getBizType());
        if (bizTypeEnum != null) {
            systemNotificationsVO.setBizTypeDesc(bizTypeEnum.getDesc());
        }

        // 设置目标渠道描述
        ChannelTypeEnum channelTypeEnum = ChannelTypeEnum.getEnumByCode(systemNotifications.getTargetChannels());
        if (channelTypeEnum != null) {
            systemNotificationsVO.setTargetChannelsDesc(channelTypeEnum.getDesc());
        }
    }
}